<?php
class News_model extends DNN_model
{
	protected  $_table = 'news';
	
	private $_title = 'title_en';
	private $_summary = 'summary_en';
	private $_body = 'body_en';
	private $_image_description = 'image_description_en';
	
	function __construct() {
		parent::__construct();
		$_title = 'title_'.$this->_language;
		$_summary = 'summary_'.$this->_language;
		$_image_description = 'image_description_'.$this->_language;
	}
	
	function get_paged_list($limit = 10, $offset = 0) {
		$this->db->select('id, '.$this->_title.' as title, '.$this->_summary.' as summary, image_thumb, image, '.$this->_body.' as body, '.$this->_image_description.' as image_description, tag, created_date');
		$this->db->from($this->_table);
		$this->db->order_by('created_date','desc');
		$this->db->limit($limit, $offset);
		return $this->db->get();
	}
	
	function get_by_id($id) {
		$this->db->select('id, '.$this->_title.' as title, '.$this->_summary.' as summary, image_thumb, image, '.$this->_body.' as body, '.$this->_image_description.' as image_description, tag, created_date');
		$this->db->from($this->_table);
		$this->db->where('id', $id);
		return $this->db->get();
	}
	
	function get_related_list($limit = 10, $offset = 0, $tag = 0) {
		$this->db->select('id, '.$this->_title.' as title, '.$this->_summary.' as summary, image_thumb, image, '.$this->_body.' as body, '.$this->_image_description.' as image_description, tag, created_date');
		$this->db->from($this->_table);
		if($tag != 0){
			$this->db->where('tag', $tag);
		}
		$this->db->order_by('created_date','desc');
		$this->db->limit($limit, $offset);
		return $this->db->get();
	}
}
?>